/*
* @Author: Jack.Hu
* @Date:   2019-03-26 18:54:01
* @Last Modified by:   Jackhzh
* @Last Modified time: 2019-03-26 20:59:54
*/

const post = ( url, data, sessionid ) => {
    var promise = new Promise((resolve, reject) => {
        //网络请求
        wx.request({
            url: url,
            data: data,
            method: 'POST',
            header: { 
                "sessionid": sessionid,
                'content-type': 'application/x-www-form-urlencoded'
            },
            success: res => {//服务器返回数据
                resolve(res);      
            },
            fail: res => {
                wx.showToast({
                    title: '服务器出小差了～',
                    icon: 'none',
                })
                reject('网络出错');
            }
        })
    });
    return promise;
}
// 封装get请求
const get = ( url, data, sessionid) => {
    var promise = new Promise((resolve, reject) => {
        //网络请求
        wx.request({
            url: url,
            data: data,
            header: {
                "sessionid": sessionid,
                'content-type': 'application/json'
            },
            success: function (res) {//服务器返回数据
                resolve(res);
            },
            fail: res => {
                wx.showToast({
                    title: '服务器出小差了～',
                    icon: 'none',
                })
                reject('网络出错');
            }
        })
    });
    return promise;
}
module.exports = {
  post,
  get
}